#ifndef _KLAS_GENERAL_HPP_
#define _KLAS_GENERAL_HPP_

#include <string>
#include <sstream>
#include <cmath>
using std::string;
using std::stringstream;

namespace klas
{
  namespace tools
  {
    class General
    {
    public:
      template<typename T>
      static T getNextPowerOfTwo(T val)
      {
        val--;
        val |= val >> 1;
        val |= val >> 2;
        val |= val >> 4;
        val |= val >> 8;
        val |= val >> 16;
        val++;

        return val;
      }

      //! Converts the object to a string using the << operator.
      template<typename T>
      static string toString(const T& obj)
      {
        stringstream ss;
        ss << obj;
        return ss.str();
      }

      //! Tests if two doubles are equal.
      /*! \param distance How far apart the numbers have to be to be considered equal. */
      static bool equals(double a, double b, double distance = .0005)
      {
        return fabs(a-b) < distance;
      }

      //! Tests is two floats are equal.
      /*! \param distance How far apart the numbers have to be to be considered equal. */
      static bool equals(float a, float b, float distance = .0005)
      {
        return fabs(a-b) < distance;
      }

    };
  }
}

#endif